<template>
  <j-modal :title="title" :width="width" :visible="visible" @ok="submitForm" @cancel="handleCancel" cancelText="暂不认证"
    okText="认证信息">
    <a-spin :spinning="confirmLoading">
      <j-form-container>
        <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
          <a-row>
            <a-col :span="24">
              <a-form-model-item label="组织名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
                <a-input v-model="model.name" placeholder="请输入组织名称"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="type">
                <j-dict-select-tag v-model="model.type" placeholder="请选择类型" dictCode="organization_type" />
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input v-model="model.address" placeholder="请输入地址"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="认证说明" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-textarea v-model="model.remark" placeholder="请输入认证说明"></a-textarea>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </j-form-container>
    </a-spin>
  </j-modal>
</template>

<script>
import { httpAction } from '../../api/manage';


export default {
  name: 'RegisterOrganizeModal',
  data() {
    return {
      title: '组织信息',
      visible: false,
      confirmLoading: false,
      width: 800,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      validatorRules: {
        name: [
          { required: true, message: '组织名称不能为空', trigger: 'blur' }
        ],
        expire: [
          { type: 'date', required: true, message: '有效期不能为空', trigger: 'change' }
        ],
        type: [
          { required: true, message: '类型不能为空', trigger: 'blur' }
        ],
      },
      url: {
        register: "/platform/cyPlatformOrganizationInfo/register",
        editBaseInfo: "/platform/cyPlatformOrganizationInfo/editBaseInfo",
      }
    }
  },
  created() {

  },
  methods: {
    register() {
      this.visible = true
      this.title = "注册信息"
    },
    edit(record) {
      this.model = Object.assign({}, record);
      this.title = "组织信息编辑"
      this.visible = true;
    },
    close() {
      this.$emit('close');
      this.visible = false;
    },
    submitCallback() {
      this.$emit('ok');
      this.visible = false;
    },
    handleCancel() {
      this.close()
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          if (!this.model.id) {
            httpurl += this.url.register;
          } else {
            httpurl += this.url.editBaseInfo;
          }
          httpAction(httpurl, this.model, 'put').then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              this.visible = false;
              window.location.reload()
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }
      })
    },
  }
}

</script>
<style lang="less"></style>